package drone.iqgc.example ;

import java.util.concurrent.CountDownLatch ;
import java.util.concurrent.TimeUnit ;

import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;

import io.mavsdk.System ;
import io.mavsdk.action.Action ;
import io.reactivex.Completable ;
import io.reactivex.Observable ;
import io.reactivex.Scheduler ;
import io.reactivex.disposables.Disposable ;
import io.reactivex.schedulers.Schedulers ;

public class Restore
{

	private static final Logger logger = LoggerFactory.getLogger ( Restore.class ) ;

	public static void main (
			String [ ] args
	)
	{
		logger.debug ( "Starting example:  restore..." ) ;

		CountDownLatch latch = new CountDownLatch ( 1 ) ;

		System drone = new System ( "60.205.58.145" , 50042 ) ;
		
		
		 drone.getTelemetry().getFlightMode()
         .subscribe(flightMode -> logger.info("Flight mode: " + flightMode));

		drone.getAction ( ).hold ( )
		.andThen(drone.getAction().land())
        .andThen(drone.getAction().disarm())
        .andThen(Completable.complete())
		.subscribe ( latch::countDown , throwable -> latch.countDown ( ) ) ;

		try
		{
			latch.await ( ) ;
		} catch ( InterruptedException ignored )
		{
			// This is expected
		}
		//
	}
}
